/*
 *  Copyright (C) Marco Aurélio Gerosa All Rights Reserved.
 *  Copyright (C) Universidade de São Paulo All Rights Reserved.
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package br.org.groupware_workbench.collabElement.coop.recommendMgr.internal;

import java.util.ArrayList;
import java.util.List;

public final class RecommendUtil {

    private RecommendUtil() {}

    /**
     * @deprecated Este método não funciona, utilize a classe
     * {@link br.org.groupware_workbench.commons.util.StringConverter} ao invés deste método. Remove a acentuação.
     * @return
     * @param passa
     */
    @Deprecated
    public static String tiraAcento(String passa) {
        passa = passa.replaceAll("[ÁÄÀÂÃ]", "A");
        passa = passa.replaceAll("[áäàâã]", "a");
        passa = passa.replaceAll("[ÉËÈÊ]", "E");
        passa = passa.replaceAll("[éëèê]", "e");
        passa = passa.replaceAll("[ÍÏÌÎ]", "I");
        passa = passa.replaceAll("[íïìî]", "i");
        passa = passa.replaceAll("[ÓÖÒÔÕ]", "O");
        passa = passa.replaceAll("[óöòôõ]", "o");
        passa = passa.replaceAll("[ÚÜÙÛ]", "U");
        passa = passa.replaceAll("[úüùû]", "u");
        passa = passa.replaceAll("Ç", "C");
        passa = passa.replaceAll("ç", "c");
        passa = passa.replaceAll("[ýÿ]", "y");
        passa = passa.replaceAll("Ý", "Y");
        passa = passa.replaceAll("ñ", "n");
        passa = passa.replaceAll("Ñ", "N");
        passa = passa.replaceAll("\n", ",");
        passa = passa.replaceAll("\t", ",");
        passa = passa.replaceAll("['<>\\|/]", "");
        return passa;
    }

    /* Remover caracteres que nao são do alfabeto */
    public static String removeChars(String texto) {
        texto = texto.replaceAll("([^a-zA-z,])", " ");
        return texto;
    }

    public static String normalizacao(String texto) {
        texto = texto.toLowerCase();
        return texto;
    }

    public static String recommendsToString(String... recommends) {
        String toReturn = "";
        for (String recommendName : recommends) {
            recommendName = recommendName.replaceAll(" ", "");
            if (!"".equals(recommendName) && !toReturn.contains(recommendName)) {
                toReturn += "," + recommendName;
            }
        }
        return toReturn.substring(1);
    }

    public static List<String> stringToRecommends(String string) {
        List<String> toReturn = new ArrayList<String>();

        /*
         * string = tiraAcento(string); string = removeChars(string); string = normalizacao(string);
         */
        String[] recommends = string.split(",");
        for (String recommend : recommends) {
            if (!recommend.trim().isEmpty()) {
                toReturn.add(recommend.trim());
            }
        }
        return toReturn;
    }
}
